<template>
  <div class="roleAdd">
    <el-form :model="perlist" :rules="rules" ref="perlist" label-width="80px">
        <el-form-item class="rolename" label="参数名称" prop="paramName">
            <el-input v-model="perlist.paramName"></el-input>
        </el-form-item>
        <el-form-item class="rolename" label="参数值" prop="paramVal">
            <el-input v-model="perlist.paramVal"></el-input>
        </el-form-item>
        <el-form-item class="rolename" label="参数模块" prop="paramMode">
            <el-input v-model="perlist.paramMode"></el-input>
        </el-form-item>
        <el-form-item class="rolename" label="描    述" prop="description">
            <el-input v-model="perlist.description"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" class="save" @click="save('perlist')">保存</el-button>
            <el-button class="quxiao" @click="closeLayer">取消</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from "axios";
export default {
  props: ["perlist"],
  name: "roleAdd",
  data() {
    return {
      rules: {
        paramName: [
          { required: true, message: "请输入参数名", trigger: "blur" },
          { min: 3, max: 20, message: "长度在 3 到 20 个字符", trigger: "blur" }
        ],
        paramVal: [
          { required: true, message: "请输入参数值", trigger: "blur" },
          { min: 3, max: 32, message: "长度在 3 到 32 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    //关闭layer弹窗
    closeLayer() {
      layer.closeAll();
    },
    save(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          //验证通过执行方法
          // alert("submit!");
          axios
            .put(
              sysparamsURL + "/" + this.perlist.paramBh,
              {
                paramName: this.perlist.paramName,
                paramVal: this.perlist.paramVal,
                paramMode: this.perlist.paramMode,
                description: this.perlist.description
              },
              {
                headers: { Authorization: appDB.get("userInfo").token }
              }
            )
            .then(res => {
              let d = res.data;
              if (d.resultCode == 0) {
                this.$parent.getSystem(); //渲染列表
                this.closeLayer(); //关闭layer弹窗
              } else {
                layer.msg(d.msg);
              }
            })
            .catch(error => {
              layer.msg("网络错误");
            });
        } else {
          // console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>

<style scoped>
.roleAdd {
  width: 80%;
  padding: 50px 10%;
  float: left;
}
.save {
  padding: 8px 40px;
  background: #38b824;
  border-color: #38b824;
  border-radius: 30px;
  float: right;
  margin-left: 30px;
}
.quxiao {
  background: #cecece;
  padding: 8px 40px;
  color: #5a5e66;
  border-radius: 30px;
  float: right;
}
</style>


